<template>
  <SysDialog draggable :title="dialog.title" :marginTop="dialog.marginTop" :visible="dialog.visible" :width="dialog.width" :height="dialog.height"
    @onClose="onClose" @onConfirm="confirm">
    <template v-slot:content>
      <!-- 内容组件 -->
      <el-form :model="dialogModel" ref="addDiapatchForm" :rules="rules" label-width="120px" size="default">
        <el-form-item prop="updateId" label="指派人员" v-if="actionValue===1">
          <!-- <el-input v-model="dialogModel.name" clearable></el-input> -->
          <el-select v-model="dialogModel.updateId" class="m-2" placeholder="请选择指派人..." size="default" clearable>
            <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
      </el-form>
      <!-- {{dialogModel  }} -->
      <div class="details">
        <abnormalForm :rowValue="dialogModel"></abnormalForm>
      </div>
      <div>
        <h2>操作日志</h2>
        <div v-for="(item, index) in dialogModel.hazardLogs" :key="index">
          操作类型:{{item.action}} 操作时间:{{ item.createTime }}
        </div>
      </div>

    </template>
  </SysDialog>
</template>

<script setup lang='ts'>
import { ref } from 'vue'
import { ElForm } from 'element-plus';
import dispatchListModel from '../composables/dispatchListModel'
import SysDialog from '@/components/SysDialog.vue';
import useDialog from '@/hooks/useDialog';
import useInstance from '@/hooks/useInstance';
import { EditType, Title } from '@/type/BaseEnum';
import abnormalForm from '@/components/Abnormal/abnormalForm.vue';
// 使用
const { dialogModel, rules } = dispatchListModel()
const addDiapatchForm = ref<InstanceType<typeof ElForm>>()
const { dialog, onClose, onShow } = useDialog()
const { global, proxy } = useInstance();
const emit = defineEmits(['saveDispatch'])
let actionValue = ref()
// 父级数据
const props = defineProps({
  userList: {
    type: Array as any,
    default: () => []
  }
})
// 保存
const confirm = () => {
  addDiapatchForm.value?.validate(isOk => {
    if (isOk) {
      emit('saveDispatch', dialogModel,actionValue.value)
      onClose()
    }
  })
}
const show = (type: string, action:number,row?: any) => {
  actionValue.value=action
  dialog.width = 850
  dialog.height = 650
  dialog.title = action===1?'指派':action===2?'完成':action===3?'终止':''
  dialog.marginTop='5vh'
  onShow()
  global.$resetForm(addDiapatchForm.value, dialogModel)
  if (type === EditType.EDIT) {
    global.$objCopy(row, dialogModel)
    // dialogModel=row
  }
}
defineExpose({
  show
})
</script>
<style scoped lang='scss'>
.details{
  margin: 0 auto;
}
</style>